/**
 * @author tmh
 * @date 2024/9/25 21:27
 * @description
 */
public class T74搜索二维矩阵 {
    public boolean searchMatrix(int[][] matrix, int target) {
        //对每一行都进行一个二分
        int m = matrix.length;
        int n = matrix[0].length;
        for (int i = 0; i < m; i++) {
            int left = 0;
            int right = n - 1;
            while (left <= right) {
                int mid = (right + left) / 2;
                if (matrix[i][mid] < target) {
                    left = mid + 1;
                } else if (matrix[i][mid] > target) {
                    right = mid - 1;
                }else {
                    return true;
                }
            }
        }
        return false;
    }
}
